package uit.com.project.iCampus.services;

import java.util.ArrayList;
import java.util.List;

import org.xmlrpc.android.XMLRPCException;

import uit.com.project.iCampus.application.ICampusApp;
import uit.com.project.iCampus.model.BuildingInfo;
import uit.com.project.iCampus.model.User;
import uit.com.project.iCampus.model.UserOnline;
import uit.com.project.iCampus.xmlparser.XMLParserAndroidUtil;
import android.util.Log;

public class ICampusAndroidServices {

	// -------------- User ---------------
	public static User findUserById(String username) {
		User result = null;
		try {
			String stringXML = (String) ICampusApp.XML_RPC_CLIENT.call(
					"ICampus.findUserById", username);
			result = XMLParserAndroidUtil.unmarshalUser(stringXML);
		} catch (XMLRPCException e) {
			Log.d("XMLRPC Exception", e.toString());
		}
		return result;
	}

	// ---------------- BuildingInfo -------------

	public static List<BuildingInfo> searchBuildngInfoWithBuildingTypeEnum(
			String buildingTypeString) {
		List<BuildingInfo> results = new ArrayList<BuildingInfo>();
		try {
			String stringXML = (String) ICampusApp.XML_RPC_CLIENT.call(
					"ICampus.searchBuildngInfoWithBuildingTypeEnum",
					buildingTypeString);
			results = XMLParserAndroidUtil.unmarshalListBuildngInfo(stringXML);
		} catch (XMLRPCException e) {
			Log.d("XMLRPC Exception", e.toString());
		}
		return results;
	}
	
	public static List<BuildingInfo> searchListBuildingInfoInRadius(String botLat, String topLat, String leftLon, String rightLon) {
		List<BuildingInfo> results = new ArrayList<BuildingInfo>();
		try {
			String stringXML = (String) ICampusApp.XML_RPC_CLIENT.call(
					"ICampus.searchListBuildingInfoInRadius",
					botLat, topLat, leftLon, rightLon);
			results = XMLParserAndroidUtil.unmarshalListBuildngInfo(stringXML);
		} catch (XMLRPCException e) {
			Log.d("XMLRPC Exception", e.toString());
		}
		return results;
	}

	// -------------- UserOnline ------------------
	public static List<UserOnline> getAllUserOnlines() {
		List<UserOnline> results = new ArrayList<UserOnline>();
		try {
			String stringXML = (String) ICampusApp.XML_RPC_CLIENT
					.call("ICampus.getAllUserOnlines");
			results = XMLParserAndroidUtil.unmarshalListUserOnline(stringXML);
		} catch (XMLRPCException e) {
			Log.d("XMLRPC Exception", e.toString());
		}
		return results;
	}
}